package net.oschina.app.adapter.newsadapter;

import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import net.oschina.app.R;
import net.oschina.app.adapter.BaseRecyclerViewAdapter;
import net.oschina.app.bean.News;
import net.oschina.app.databinding.ViewNewsRvItemBinding;

import java.util.List;

/**
 * Created by wuer on 2017/4/1/001.
 */

public class NewsAdapter extends BaseRecyclerViewAdapter {
    private List<News> mNewsList;
    public NewsAdapter(List<News> newList){
        super();
        this.mNewsList=newList;
    }

    @Override
    public android.support.v7.widget.RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView=mInflater.inflate(R.layout.view_news_rv_item,parent,false);
        NewsHolder holder=new NewsHolder(itemView);
        itemView.findViewById(R.id.today).setVisibility(View.VISIBLE);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        NewsHolder newsHolder= (NewsHolder) holder;
        News news=mNewsList.get(position);
        //资讯页面数据绑定
        ViewNewsRvItemBinding binding = DataBindingUtil.bind(newsHolder.itemView);
        binding.setNews(news);
        binding.setCommentCount(news.getCommentCount()+"");
    }

    @Override
    public int getItemCount() {
        return mNewsList.size();
    }
    public class NewsHolder extends RecyclerView.ViewHolder{
        public TextView mTextView;
        public NewsHolder(View itemView) {
            super(itemView);
        }
    }
}
